﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrayParrot.Web.Formly;

namespace FimetContoDeposito.BLL.Metadata
{
    public class AnagraficaArticoliMetadata
    {
        [FieldGroup(GroupName = "primo", Row = 1, Index = 1, NumberOfColumns = 12)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "Magazzino",
                               Placeholder = "Indicare il magazzino...",
                               Required = true,
                               Disabled = true,
                               Callback = "/api/Customers/CustomersForDDL", ForceLoad = true)]
        public Guid IdCliente { get; set; }

        /**/
        [FieldGroup(GroupName = "secondo", Row = 2, Index = 1, NumberOfColumns = 6)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptionsAttribute(Label = "Codice",
            Placeholder = "Indicare il codice articolo (max 50 caratteri)",
            Required = true,
            MinLength = 0,
            MaxLength = 50)]
        public string Codice { get; set; }

        [FieldGroup(GroupName = "secondo", Row = 2, Index = 2, NumberOfColumns = 6)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptionsAttribute(Label = "Descrizione",
            Placeholder = "Indicare la descrizione (max 200 caratteri)",
            Required = true,
            MinLength = 0,
            MaxLength = 200)]
        public string Descrizione { get; set; }

        /**/
        //[FieldGroup(GroupName = "terzo", Row = 3, Index = 1, NumberOfColumns = 2)]
        //[FormFieldAttribute(Type = FormFieldTypes.Select)]
        //[SelectTemplateOptions(Label = "Fornitore",
        //                       Required = true,
        //                       Callback = "/api/Common/LoadFornitori", ForceLoad = true)]
        //public Guid IdFornitore { get; set; }

        [FieldGroup(GroupName = "terzo", Row = 3, Index = 1, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "U.M.",
                               Required = true,
                               Callback = "/api/UnitaDiMisura/LoadUnitaDiMisura", ForceLoad = true)]        
        public Guid UnitaDiMisura { get; set; }

        [FieldGroup(GroupName = "terzo", Row = 3, Index = 2, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptionsAttribute(Label = "Qta/Pacco",
            Required = false, Value = 1)]
        public decimal? QtaPacco { get; set; }

        [FieldGroup(GroupName = "terzo", Row = 3, Index = 3, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Checkbox)]
        [CheckBoxTemplateOptions(Label = "Abilitato", Required = true, DefaultValue = true)]
        public bool IsAbilitato { get; set; }

        [Events(Event = EventTypes.OnChange, Callback = "ShowImg")]
        [FieldGroup(GroupName = "terzo", Row = 3, Index = 4, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.GrayParrotFileUpload)]
        [GrayParrotFileUploadOptionsAttribute(Label = "",
            Required = false,
            Folder = @"\Profili_imgs")]
        public string Foto { get; set; }

        /**/
        [AddOn(Position = Position.Right, Text = "", Class = "glyphicon glyphicon-remove", OnClick = "CancellaFornitore")]
        [FieldGroup(GroupName = "quarto", Row = 4, Index = 1, NumberOfColumns = 4)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "Fornitore",
                               Placeholder = "Indicare il Fornitore dell'articolo...",
                               Required = false,
                               Callback = "/api/Common/LoadFornitori", ForceLoad = true)]
        public Guid Fornitore { get; set; }

        [Events(Event = EventTypes.OnLoad, Callback = "LoadCodiciFornitori")]
        [Events(Event = EventTypes.OnChange, Callback = "TrovaArticolo")]
        [FieldGroup(GroupName = "quarto", Row = 4, Index = 2, NumberOfColumns = 4)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "Cod. Fornitore",
                               Required = false,
                               Callback = "/api/AnagraficaCodiciFornitori/LoadCodiciFornitoriAssegnabili", ForceLoad = true, DependsBy = "IdCliente, Fornitore")]
        public Guid CodiceFornitore { get; set; }

        /**/
        [FieldGroup(GroupName = "quinto", Row = 5, Index = 1, NumberOfColumns = 3)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "Tipologia",
                               Required = false,
                               Callback = "/api/TipologiaArticolo/LoadTipologieArticoli", ForceLoad = true)]
        public Guid Tipologia { get; set; }

        [FieldGroup(GroupName = "quinto", Row = 5, Index = 2, NumberOfColumns = 3)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptions(Label = "P. Teorico (Kg.)", 
            Required = false, Disabled = false, Value = 0.0)]
        public decimal? PesoTeorico { get; set; }

        [FieldGroup(GroupName = "quinto", Row = 5, Index = 3, NumberOfColumns = 3)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptionsAttribute(Label = "Dimensioni",
            Required = false,
            MinLength = 0,
            MaxLength = 50)]
        public string Dimensioni { get; set; }

        [FieldGroup(GroupName = "quinto", Row = 5, Index = 4, NumberOfColumns = 3)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptionsAttribute(Label = "Serie/Famiglia",
            Required = false,
            MinLength = 0,
            MaxLength = 50)]
        public string SerieFamiglia { get; set; }

        /**/
        [FieldGroup(GroupName = "sesto", Row = 6, Index = 1, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptions(Label = "Scorta Min.", Placeholder = "Indica la scorta minima...",
            Required = false, Disabled = false, Value = 0.0)]
        public decimal? ScortaMinima { get; set; }

        [FieldGroup(GroupName = "sesto", Row = 6, Index = 2, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "U.M. Fatt.",
                               Placeholder = "Indicare l'unità di misura...",
                               Required = false,
                               Callback = "/api/UnitaDiMisura/LoadUnitaDiMisura", ForceLoad = true)]
        public Guid UMFatt { get; set; }

        [FieldGroup(GroupName = "sesto", Row = 6, Index = 3, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptions(Label = "P. Unitario", Placeholder = "Indica il prezzo unitario...",
            Required = false, Disabled = false, Value = 0.0)]
        public decimal? PrezzoUnitario { get; set; }

        [FieldGroup(GroupName = "sesto", Row = 6, Index = 4, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptions(Label = "Sconto", Placeholder = "Indica lo sconto fornitore...",
            Required = false, Disabled = false, Value = 0.0)]
        public decimal? ScontoFornitore { get; set; }

        /**/
        [FieldGroup(GroupName = "settimo", Row = 7, Index = 1, NumberOfColumns = 12)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptions(Label = "Note",
            Placeholder = "Indicare le eventuali note (max 200 caratteri)",
            Required = false,
            MinLength = 0,
            MaxLength = 200)]
        public string Note { get; set; }

        /**/
        [FormFieldAttribute(Type = FormFieldTypes.Checkbox)]
        [CheckBoxTemplateOptions(Label = "XXXX", Placeholder = "", Required = false, DefaultValue=false, Hidden=true)]
        public bool IsXxxx { get; set; }

        //
        public AnagraficaArticoliMetadata()
        {

        }
    }

    public class AnagraficaArticoliMetadataEdit
    {
        [FieldGroup(GroupName = "primo", Row = 1, Index = 1, NumberOfColumns = 12)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "Magazzino",
                               Placeholder = "Indicare il magazzino...",
                               Required = true,
                               Disabled = true,
                               Callback = "/api/Customers/CustomersForDDL", ForceLoad = true)]
        public Guid IdCliente { get; set; }

        /**/
        [FieldGroup(GroupName = "secondo", Row = 2, Index = 1, NumberOfColumns = 6)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptionsAttribute(Label = "Codice",
            Placeholder = "Indicare il codice articolo (max 50 caratteri)",
            Required = true,
            MinLength = 0,
            MaxLength = 50)]
        public string Codice { get; set; }

        [FieldGroup(GroupName = "secondo", Row = 2, Index = 2, NumberOfColumns = 6)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptionsAttribute(Label = "Descrizione",
            Placeholder = "Indicare la descrizione (max 200 caratteri)",
            Required = true,
            MinLength = 0,
            MaxLength = 200)]
        public string Descrizione { get; set; }

        /**/
        //[FieldGroup(GroupName = "terzo", Row = 3, Index = 1, NumberOfColumns = 2)]
        //[FormFieldAttribute(Type = FormFieldTypes.Select)]
        //[SelectTemplateOptions(Label = "Fornitore",
        //                       Required = true,
        //                       Callback = "/api/Common/LoadFornitori", ForceLoad = true)]
        //public Guid IdFornitore { get; set; }

        [FieldGroup(GroupName = "terzo", Row = 3, Index = 1, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "U.M.",
                               Required = true,
                               Callback = "/api/UnitaDiMisura/LoadUnitaDiMisura", ForceLoad = true)]
        public Guid UnitaDiMisura { get; set; }

        [FieldGroup(GroupName = "terzo", Row = 3, Index = 2, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptionsAttribute(Label = "Qta/Pacco",
            Required = false, Value = 1)]
        public decimal? QtaPacco { get; set; }

        [FieldGroup(GroupName = "terzo", Row = 3, Index = 3, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Checkbox)]
        [CheckBoxTemplateOptions(Label = "Abilitato", Required = true, DefaultValue = true)]
        public bool IsAbilitato { get; set; }

        [Events(Event = EventTypes.OnChange, Callback = "ShowImg")]
        [FieldGroup(GroupName = "terzo", Row = 3, Index = 4, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.GrayParrotFileUpload)]
        [GrayParrotFileUploadOptionsAttribute(Label = "",
            Required = false,
            Folder = @"\Profili_imgs")]
        public string Foto { get; set; }

        /**/
        [AddOn(Position = Position.Right, Text = "", Class = "glyphicon glyphicon-remove", OnClick = "CancellaFornitore")]
        [FieldGroup(GroupName = "quarto", Row = 4, Index = 1, NumberOfColumns = 4)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "Fornitore",
                               Placeholder = "Indicare il Fornitore dell'articolo...",
                               Required = false,
                               Callback = "/api/Common/LoadFornitori", ForceLoad = true)]
        public Guid Fornitore { get; set; }

        [Events(Event = EventTypes.OnChange, Callback = "TrovaArticolo")]
        [FieldGroup(GroupName = "quarto", Row = 4, Index = 2, NumberOfColumns = 4)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "Cod. Fornitore",
                               Required = false,
                               Callback = "/api/AnagraficaCodiciFornitori/LoadCodiciFornitoriAssegnabiliEAssegnato", ForceLoad = true, DependsBy = "Id, IdCliente, Fornitore")]
        public Guid CodiceFornitore { get; set; }

        /**/
        [FieldGroup(GroupName = "quinto", Row = 5, Index = 1, NumberOfColumns = 3)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "Tipologia",
                               Required = false,
                               Callback = "/api/TipologiaArticolo/LoadTipologieArticoli", ForceLoad = true)]
        public Guid Tipologia { get; set; }

        [FieldGroup(GroupName = "quinto", Row = 5, Index = 2, NumberOfColumns = 3)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptions(Label = "P. Teorico (Kg.)",
            Required = false, Disabled = false, Value = 0.0)]
        public decimal? PesoTeorico { get; set; }

        [FieldGroup(GroupName = "quinto", Row = 5, Index = 3, NumberOfColumns = 3)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptionsAttribute(Label = "Dimensioni",
            Required = false,
            MinLength = 0,
            MaxLength = 50)]
        public string Dimensioni { get; set; }

        [FieldGroup(GroupName = "quinto", Row = 5, Index = 4, NumberOfColumns = 3)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptionsAttribute(Label = "Serie/Famiglia",
            Required = false,
            MinLength = 0,
            MaxLength = 50)]
        public string SerieFamiglia { get; set; }

        /**/
        [FieldGroup(GroupName = "sesto", Row = 6, Index = 1, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptions(Label = "Scorta Min.", Placeholder = "Indica la scorta minima...",
            Required = false, Disabled = false, Value = 0.0)]
        public decimal? ScortaMinima { get; set; }

        [FieldGroup(GroupName = "sesto", Row = 6, Index = 2, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Select)]
        [SelectTemplateOptions(Label = "U.M. Fatt.",
                               Placeholder = "Indicare l'unità di misura...",
                               Required = false,
                               Callback = "/api/UnitaDiMisura/LoadUnitaDiMisura", ForceLoad = true)]
        public Guid UMFatt { get; set; }

        [FieldGroup(GroupName = "sesto", Row = 6, Index = 3, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptions(Label = "P. Unitario", Placeholder = "Indica il prezzo unitario...",
            Required = false, Disabled = false, Value = 0.0)]
        public decimal? PrezzoUnitario { get; set; }

        [FieldGroup(GroupName = "sesto", Row = 6, Index = 4, NumberOfColumns = 2)]
        [FormFieldAttribute(Type = FormFieldTypes.Number)]
        [NumericTemplateOptions(Label = "Sconto", Placeholder = "Indica lo sconto fornitore...",
            Required = false, Disabled = false, Value = 0.0)]
        public decimal? ScontoFornitore { get; set; }

        /**/
        [FieldGroup(GroupName = "settimo", Row = 7, Index = 1, NumberOfColumns = 12)]
        [FormFieldAttribute(Type = FormFieldTypes.Input)]
        [TextTemplateOptions(Label = "Note",
            Placeholder = "Indicare le eventuali note (max 200 caratteri)",
            Required = false,
            MinLength = 0,
            MaxLength = 200)]
        public string Note { get; set; }

        [FormFieldAttribute(Type = FormFieldTypes.Checkbox)]
        [CheckBoxTemplateOptions(Label = "XXXX", Placeholder = "", Required = false, DefaultValue = false, Hidden = true)]
        public bool IsXxxx { get; set; }

        //
        public AnagraficaArticoliMetadataEdit()
        {

        }
    }
}
